#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const ll N = 1e11;

int n, d;
ll level;
vector<ll> v;
vector<int> c;

bool check(ll mid) {
    ll sum = 0;
    int index = 0;
    for (int i = 0; i < d; i++) {
        while (sum < mid && index < n) {
            sum += v[index++];
            if (mid == level) c[index - 1] = i + 1;
        }
        if (sum < mid) return false;
        sum = sum / 2;
    }
    return true;
}

void solve() {
    cin >> n >> d;
    v.resize(n);
    c.resize(n, d);
    for (int i = 0; i < n; i++) cin >> v[i];
    ll l = 0, r = N;
    while (l <= r) {
        ll mid = l + (r - l) / 2;
        if (check(mid)) {
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    cout << r << endl;
    level = r;
    check(r);
    for (int i = 0; i < n; i++) {
        cout << c[i] << endl;
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();

    return 0;
}